package com.shop.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shop.pojo.DtsGoodsProduct;
import com.shop.mapper.DtsGoodsProductMapper;
import com.shop.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @ClassName DtsGoodsProductServiceImpl
 * @Author xiao宋
 * @Date 21:33  2022/10/13
 * @Version 1.0
 * @Description TODO
 */
@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {
    @Autowired
    DtsGoodsProductMapper goodsProductMapper;
    @Override
    public long getTotal() {
        LambdaQueryWrapper<DtsGoodsProduct> w=new LambdaQueryWrapper<>();
        w.eq(DtsGoodsProduct::getDeleted, false);

        Integer total=goodsProductMapper.selectCount(w);
        return total;
    }

    @Override
    public void insert(DtsGoodsProduct product) {
        product.setDeleted(false);
        product.setUpdateTime(new Date());
        product.setAddTime(new Date());
        goodsProductMapper.insert(product);
    }

    @Override
    public void deleteById(Integer goodsId) {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId, goodsId);
        goodsProductMapper.delete(wrapper);
    }
}
